import {
    initGlobalState
} from 'qiankun'
import {
    getUser
} from './index'
import store from '../store'
import {
    setUser
} from '../store/userReducer'

// 初始化 state
const state = {
    user: getUser()
}
const actions = initGlobalState(state)
//  state监听 第二个参数为true时，会立即执行
actions.onGlobalStateChange((state, prev) => {
    // state: 变更后的状态; prev 变更前的状态
    if (!state.user && prev.user) {
        store.dispatch(setUser(null))
    }
})
export default actions